import { Component, OnInit } from '@angular/core';
import {ActivatedRoute} from "@angular/router";
import {HeroService} from "../hero.service";
import {Article} from "../Article";
import { Location } from '@angular/common';
import {UserService} from "../user.service";

declare var editormd: any;

@Component({
  selector: 'app-article-detail',
  templateUrl: './article-detail.component.html',
  styleUrls: ['./article-detail.component.css']
})
export class ArticleDetailComponent implements OnInit {
  article:Article = new Article();
  constructor(private route: ActivatedRoute,private heroService: HeroService,private location: Location,private userService: UserService) {
  }

  ngOnInit() {
    this.getArticle();
  }
  getArticle():void {
    const id = +this.route.snapshot.paramMap.get('id');
    this.heroService.getHero(id)
      .subscribe(heroes => {
        this.article = heroes.data;
        editormd.markdownToHTML("test-editormd-view2", {
          markdown:this.article.articleContent,
          htmlDecode: "style,script,iframe",
          emoji: true,
          taskList: true,
          tex: true, // 默认不解析
          flowChart: true, // 默认不解析
          sequenceDiagram: true, // 默认不解析
          codeFold: true
        });
      });
  }
}
